package model

import "heartbeat/database/schema"
import "heartbeat/database"

type UserBean struct{}

func (bean *UserBean) Add(user *schema.User) (int64, error) {
	engine := database.GetDBConnect()
	return engine.Insert(user)
}

func (bean *UserBean) FindByUsername(name string) (count int64, err error) {
	engine := database.GetDBConnect()
	session := engine.SQL("SELECT count(*) FROM user where name = ? limit 1", name)
	count, err = session.Count(new(schema.User))
	return
}

func (bean *UserBean) FindByUsernameAndPassword(name string, password string) (count int64, err error) {
	engine := database.GetDBConnect()
	session := engine.SQL("SELECT count(*) FROM user where name = ? and password = ? limit 1", name, password)
	count, err = session.Count(new(schema.User))
	return
}
